package headfirst.combined.djview;
  
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class StressBar extends JProgressBar implements Runnable { 
    JProgressBar progressBar;
	Thread thread;

	public StressBar() {
		thread = new Thread(this);
		setMaximum(100);
		setOrientation(SwingConstants.VERTICAL);
		setStringPainted(true);
		setForeground(Color.green);
		setBackground(Color.black);
		thread.start();
	}

	public void run() {
		int i = 0;
		for(;;) {
			int value = getValue();	
			if(value>80)setForeground(Color.red);
			if(value>60 && value<=80)setForeground(Color.yellow);
			if(value>20 && value<=60)setForeground(Color.green);
			if(value<=20 && value>0) setForeground(Color.blue);
			
			repaint();
			try {
				Thread.sleep(1);
			} catch (Exception e) {};
		}
	}
}
